<template>
  <avue-crud
    :table-loading="loading"
    :option="option"
    :data="list"
    @on-load="onLoad"
    @row-save="rowSave"
    @row-update="rowUpdate"
    @refresh-change="refreshChange"
    @row-del="rowDel"
  />
</template>
<script>
import { option } from '@/option/tenant/supplier/bak/customer-record'
import { getList, save, remove } from '@/api/supplier/bak/customerrecord'
export default {
  name: 'Customer',
  props: ['changeId'],
  data() {
    return {
      loading: false,
      option: option.call(this),
      list: []
    }
  },
  methods: {
    refreshChange() {
      this.onLoad()
    },
    onLoad() {
      this.loading = true
      getList({ changeId: this.changeId }).then(res => {
        this.list = res.data.data
        this.loading = false
      })
    },
    rowSave(row, done, loading) {
      save({ ...row, changeId: this.changeId }).then(
        () => {
          this.onLoad()
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          done()
        },
        error => {
          window.console.log(error)
          loading()
        }
      )
    },
    rowUpdate(row, index, done, loading) {
      save(row).then(
        () => {
          this.onLoad()
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          done()
        },
        error => {
          window.console.log(error)
          loading()
        }
      )
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove(row.id)
        })
        .then(() => {
          this.onLoad()
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
        })
    }
  }
}
</script>

<style></style>
